package com.zhsj.OkeHomeConsumption.ui.activity.citypartner;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hjq.bar.TitleBar;
import com.orhanobut.hawk.Hawk;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.MyActivity;
import com.zhsj.OkeHomeConsumption.empty.CityLookpayeeBean;
import com.zhsj.OkeHomeConsumption.empty.CityzongsouruBean;
import com.zhsj.OkeHomeConsumption.empty.FormalUserInfo;
import com.zhsj.OkeHomeConsumption.ui.activity.citypartner.mvp.LookpayeePresenter;
import com.zhsj.OkeHomeConsumption.ui.activity.citypartner.mvp.LookpayeeUIInterFace;
import com.zhsj.OkeHomeConsumption.utils.SharedPreferanceUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 城市合伙人--- 收入记录
 */
public class LookpayeeActivity extends MyActivity  {

    @BindView(R.id.recy)
    RecyclerView recy;
    @BindView(R.id.lookpayee_title)
    TitleBar lookpayeeTitle;

    private FormalUserInfo userinfo;



    private SharedPreferanceUtils mSharePreferanceUtils = null;

    private List<CityLookpayeeBean> citylook_list = null;

    private List<CityzongsouruBean> zongsouru_list = null;

    private LookAdapter lookadapter = null;


    private int flage = -1;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_lookpayee;
    }

    @Override
    protected int getTitleId() {
        return R.id.lookpayee_title;
    }

    @Override
    protected void initView() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //设置布局管理器
        recy.setLayoutManager(layoutManager);
        //设置为垂直布局，这也是默认的
        layoutManager.setOrientation(OrientationHelper.VERTICAL);
        Intent intent = getIntent();
        flage = intent.getIntExtra("flage", -1);
    }

    @Override
    protected void initData() {
        userinfo = Hawk.get(Constants.SHARED_PERFERENCE_USERINFO);

        String list_size = "0";
        switch (flage) {
            case 0:
                //今日收入
                lookpayeeTitle.setTitle("今日收入记录");
                Intent intent2 = getIntent();
                citylook_list = (List<CityLookpayeeBean>) intent2.getSerializableExtra("extractCashRecordarr_list");
                if(citylook_list!=null){
                    list_size = citylook_list.size()+"";
                }
                String str2 = intent2.getStringExtra("extractCash");
                lookadapter = new LookAdapter();

                    View headerView2 = getHeaderView(empty(list_size), empty(str2));
                    lookadapter.addHeaderView(headerView2);
                    recy.setAdapter(lookadapter);


                break;
            case 2:
                //已提现
                lookpayeeTitle.setTitle("提现记录");
                Intent intent = getIntent();
                citylook_list = (List<CityLookpayeeBean>) intent.getSerializableExtra("extractCashRecordarr_list");
                if(citylook_list!=null){
                    list_size = citylook_list.size()+"";
                }
                String str = intent.getStringExtra("extractCash");
                lookadapter = new LookAdapter();
                View headerView = getHeaderView(empty(list_size), empty(str));
                lookadapter.addHeaderView(headerView);
                recy.setAdapter(lookadapter);
                break;
            case 3:
                //账户余额
                lookpayeeTitle.setTitle("预计收入记录");
                Intent intent1 = getIntent();
                citylook_list = (List<CityLookpayeeBean>) intent1.getSerializableExtra("extractCashRecordarr_list");
                if(citylook_list!=null){
                    list_size = citylook_list.size()+"";
                }
                String str1 = intent1.getStringExtra("extractCash");
                lookadapter = new LookAdapter();
                View headerView1 = getHeaderView(empty(list_size), empty(str1));
                lookadapter.addHeaderView(headerView1);
                recy.setAdapter(lookadapter);
                break;
        }


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }





    private String empty(String str) {
        if (str.equals("null")) {
            return "0";
        }
        return str;
    }

    private View getHeaderView(String totalCount, String todayIncome) {
        View view = getLayoutInflater().inflate(R.layout.item_lookpayeehead_layout, (ViewGroup) recy.getParent(), false);
        TextView shoukuan_text = view.findViewById(R.id.shoukuan_text);
        TextView price_text = view.findViewById(R.id.price_text);
        if (flage == 2) {
            shoukuan_text.setVisibility(View.GONE);
            price_text.setText("已提现：¥" + todayIncome);
        } else if (flage == 3) {
            shoukuan_text.setVisibility(View.GONE);
            price_text.setText("账户余额：¥" + todayIncome);
        } else {
            shoukuan_text.setText("收款笔数  " + totalCount);
            price_text.setText("收款共计：¥" + todayIncome);
        }

        return view;
    }

    public class LookAdapter extends BaseQuickAdapter<CityLookpayeeBean, BaseViewHolder> {
        public LookAdapter() {
            super(R.layout.item_lookpayee_layout, citylook_list);
        }

        @Override
        protected void convert(BaseViewHolder helper, final CityLookpayeeBean item) {
            helper.setText(R.id.name_text, item.getPayerUserName())
                    .setText(R.id.timer_text, String.valueOf(item.getCreateTime()))
                    .setText(R.id.price_text, "+" + item.getAmount());

        }
    }


}
